<template name="sendcar">
	<!-- 入库单列表 -->
	<view class="mypage">
		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="输入单号" v-model="keyword"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-blue shadow-blur round" @tap="handelSearch">搜索</button>
			</view>
		</view>

		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" v-for="(item,index) in orderList"
				:key="index" @click="openDetail(index)">

				<view class="flex-just-between bottom-border top-wrap">
					<text class="text-blue text-bold">单号：{{ item.BILLNO }}</text>
					<view class="cu-capsule radius">
						<view class='cu-tag bg-blue sm'>
							<text class='cuIcon-medal'></text>
						</view>
						<view class="cu-tag line-brown sm">
							{{ index+1}}
						</view>
					</view>
				</view>

				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">来源：</text>
					<text>{{ billFrom[item.BILLFROM] || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">状态：</text>
					<text :class="item.BILLSTATUS==1?'text-green':'text-red' ">
						{{ orderStatus[item.BILLSTATUS]  }}
					</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">集团：</text>
					<text>{{ item.GROUPNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">组织：</text>
					<text>{{ item.ORGNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text class="card-label text-black">部门：</text>
					<text> {{ item.DEPTNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-green"></text>
					<text class="card-label text-black">供应商：</text>
					<text>{{ item.SUPPLYNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-blue"></text>
					<text class="card-label text-black">申请人：</text>
					<text>{{ item.APPLYER || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-gray"></text>
					<text class="card-label text-black">日期：</text>
					<text>{{ item.BILLDATE || '' }}</text>
				</view>
				<!-- <view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text>规格：{{ '52.5R '}} </text> 
					<text class="text-blue">&emsp; {{ '500吨'}}&emsp;</text> |
					<text class="text-red">&emsp;￥{{ '32.00'}}</text>
				</view> -->

				<!-- <view class="flex-just-between top-border margin-top btn-wrap">
					<button class="cu-btn round lines-gray" >出库</button>
					<button class="cu-btn round lines-gray" >移位</button>
				</view> -->


			</view>

		</view>

	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import api from '@/common/api.js'
	import utils from '@/common/util.js'
	let _self, page = 1,
		total = 1,
		pageTitle, type, ajaxurl, Stype;
	let query = {
		"category": "",
		"page": 1,
		"rows": 5,
		"sidx": "",
		"sord": "",
		"queryJson": {},
		"userId": "",
		"account": ""
	}
	let queryJson = {};
	export default {
		computed: mapState(['userInfo', 'baseUrl']),
		data() {
			return {
				title: '列表',
				orderList: [],
				label01: '订单',
				keyword: '',
				billFrom: {
					0: '手工单',
					1: '申请单',
					2: '供货清单',
					3: '采购订单'
				},
				orderStatus: {
					0: '未审核',
					1: '已审核',
					5: '审核中'
				}
			};
		},
		onLoad(params) {
			_self = this
			_self.title = params.n
			Stype = params.sqlTbName
			queryJson = {}
			getApp().globalData.queryJsonLS = null
			pageTitle = params.sqlTbName == '1' ? '出库单' : '入库单';
			type = params.mt
			page = 1;
			total = 1;
			query.type = params.sqlTbName == '1' ? '1' : '0';
			params.sqlTbName // 0吨包入库，1吨包出库
			query.userId = _self.userInfo.UserId
			query.account = _self.userInfo.Account
			query.category = 'SUP_PURINSTORE'
			// console.log(params)
			this.getNewsList();
		},
		//下拉刷新
		onPullDownRefresh: function() {
			// 重置分页及数据
			page = 1;
			total = 1;
			this.getNewsList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			uni.showToast({
				"title": "数据已刷新",
				icon: "none"
			});
		},

		onNavigationBarButtonTap(e) {
			this.listenOnce()
			uni.navigateTo({
				url: '/pages/public/query?type=menu1005'
			})
		},

		// 加载更多
		onReachBottom: function() {
			this.getNewsList();
		},
		methods: {
			// 初始监听
			listenOnce() {
				uni.$off('reload')
				uni.$once("reload", function(data) {
					queryJson = {
						...queryJson,
						...data
					}
					getApp().globalData.queryJsonLS = queryJson
					_self.handelSearch()
				});
			},
			handelSearch() {
				console.log(_self.keyword);
				queryJson.BILLNO = _self.keyword;
				page = 1;
				total = 1;
				this.orderList = [];
				this.getNewsList();
			},
			getNewsList() {
				if (page > total) {
					return uni.showToast({
						icon: 'none',
						title: '没有数据了。'
					})
				}
				queryJson.BTYPE = '3';
				query.page = page;
				query.queryJson = JSON.stringify(queryJson);
				let URL = '/api/APPCommon/TonCementGetList' // api.apiPublic.getOrderList
				// console.log(query);
				// console.log(URL);
				this.axios({
					url: URL,
					data: query,
					isLoading: 1
				}).then(res => {
					// console.log(77,res);
					let {
						Result
					} = res
					if (page == 1) {
						_self.orderList = Result.rows
						if (Result.rows.length == 0) {
							utils.tips('暂无数据！');
						}
						utils.setPageTitle(pageTitle + '列表(' + Result.records + ')')
					} else {
						_self.orderList = _self.orderList.concat(Result.rows)
					}
					total = Result.total
					page++
				})
			},
			openDetail: function(e) {
				// console.log(e);
				let url = 'over-detail?id=' +
					_self.orderList[e].BILLNO + '&dbt=' +
					Stype + '&item=' + encodeURIComponent(JSON.stringify(_self.orderList[e]));

				if (Stype == 2) {
					url = 'submit-out?id=' +
						_self.orderList[e].BILLNO + '&dbt=' +
						Stype + '&item=' + encodeURIComponent(JSON.stringify(_self.orderList[e]));
				}

				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style scoped>
	.card-list-wrapper {
		width: 710upx;
		height: 100upx;
		margin: 0 auto;
	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}

	.card-label {
		display: inline-block;
		width: 150upx;
	}

	.top-border {
		border-top: 1upx solid rgba(0, 0, 0, .1);
	}

	.top-wrap {
		padding-bottom: 20upx;
		margin-bottom: 20upx;
	}

	.bottom-border {
		border-bottom: 1upx solid rgba(0, 0, 0, .1);
	}

	.btn-wrap {
		padding-top: 20upx;
	}
</style>